var ComplateProject = function(){
	
	var ps = new ProjectSource();
	var project_id ='-1';
	//下载 文件
	var downloadUrl = function(s, m, rec){
		return "<a href='../task/downloadFile.form?fileId="+s+"'>下载</a>";
	};
	//附件列表
	var fileStore = new Ext.data.JsonStore(
			{
				url : '../task/searchTaskUpLoadFile.form?timesnap='+new Date().getTime(),
				baseParams: {exeId: '-1'},
				root : 'result',
				fields: ['ACCESSORY_ID', 'ACCESSORY_NAME', 'UPLOAD_DATE','FILE_SIZE','UPLOAD_NAME','ACCESSORY_DESC','USER_NAME'],
				listeners : {
					scope : this,
					beforeload : function(thiz) {
						thiz.baseParams = { exeId : project_id };
					}
				}
			});
	var fileGrid = new Ext.grid.GridPanel({
		width : 900,
		height : 150,
		store : fileStore,
		columns : [{header:'附件名称',width: 150,dataIndex:'ACCESSORY_NAME'},
		           {header:'上传日期',width: 150,dataIndex:'UPLOAD_DATE'},
		           {header:'文件大小(K)',width: 250,dataIndex:'FILE_SIZE'},
		           {header:'上传人',width: 250,dataIndex:'USER_NAME'},
		           {header: '操作',width: 50, dataIndex: 'ACCESSORY_ID',renderer:downloadUrl}
		           ],
   		bbar:new Ext.PagingToolbar({
   		   pageSize: 5,
            store: fileStore,
            displayInfo: true,
            displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
            emptyMsg: "没有记录..."
           })
	});
	var fileUploadInfo = new Ext.form.FieldSet({
		title : '附件信息',
		collapsible : true,
		autoHeight : true,
		width : 930, 
		items : [fileGrid]
	});
	var completeStore = new Ext.data.JsonStore(
			{
				url : '../project/searchProjects.form?status=30&timesnap=' + new Date().getTime(),
				root : 'result',
				fields : [ 'PROJECT_ID', 'PROJECT_NAME', 'AREA_ID',
						'PROJECT_TYPE', 'EST_AMT', 'PROJECT_CREATE_DT',
						'EST_DT', 'JOIN_LEADER', 'CUSTOMER_NAME', 'STAFF_NUM',
						'CONTACT_PERSON', 'OFF_TEL', 'MOBILE', 'EMAIL',
						'PROJECT_TARGET', 'CUST_REQ', 'SERVICE_REQ',
						'IMP_FUNC', 'OWNER_PROVIDE', 'REMARK', 'COMPETITOR',
						'PROJECT_OWNER', 'INVOLVE_DT', 'ADVANTAGE',
						'DISADVANTAGE', 'CREATE_USER', 'CREATE_DT', 'MOD_USER',
						'MOD_DT' ],
				listeners : {
					scope : this,
					beforeload : function(thiz) {
						thiz.baseParams = {
							searchName : searchName.getValue(),
							searchArea : searchArea.getValue(),
							searchComplateDate : searchComplateDate.getValue() ? searchComplateDate.getValue().format('Y-m-d') : ''
						};
					}
				}
			});
	var comGrid = new Ext.grid.GridPanel({
		width : 930,
		height : 150,
		scope : this,
		store : completeStore,
		listeners : {
			scope : this,
			rowmousedown : function(grid,index,e){
				var data = grid.store.getAt(index).data;
				ps.setCompValueAndDisabled(data);
				ps.projectIsVs.setValue(true);
				project_id =data.PROJECT_ID;
				//附件信息
				fileStore.reload({params:{exeId:data.PROJECT_ID}});
			}
		},
		columns : [{header:'项目编号',width: 150,dataIndex:'PROJECT_ID'},
		           {header:'项目名称',width: 100, sortable: true,dataIndex:'PROJECT_NAME'},
		           {header:'所属区域',dataIndex:'AREA_ID',renderer:function(value,row){return ps.getGridAreaMap()[value];}},
		           {header:'项目类型',renderer:ps.renderprojectType,dataIndex:'PROJECT_TYPE'},
		           {header:'业务提供',width: 170,dataIndex:'OWNER_PROVIDE'},
		           {header:'开始时间',dataIndex:'PROJECT_CREATE_DT'},
		           {header:'计划结束时间',dataIndex:'EST_DT'},
		           {header:'估算金额',renderer: 'usMoney',dataIndex:'EST_AMT'}],
       bbar:new Ext.PagingToolbar({
		 pageSize: 5,
         store: completeStore,
         displayInfo: true,
         displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
         emptyMsg: "没有记录..."
       })
	});
	
	// 查询条件---begin
	var searchName = new Ext.form.TextField({
		fieldLabel : '项目名称',
		width : 180
	});
	
	var searchArea = new Ext.form.ComboBox( {
		fieldLabel : '归属区域',
		//hiddenName : 'type',
		//store: ,
		mode : 'local',
		displayField : 'name',
		triggerAction : 'all',
		editable : false,
		valueField : 'id',
		typeAhead : true,
		width : 150,
		emptyText : '---请选择---',
		selectOnFocus : true
	});
	
	var searchComplateDate = new Ext.form.DateField( {
		fieldLabel : '竣工时间',
		format : 'Y-m-d',
		width : 150
	});
	
	var btn_search = new Ext.Button({
		text : '查询',
		iconCls: 'icon-search',
		handler: function (){searchProject();}
	});
	// 查询条件---end
	this.comPanel = new Ext.form.FormPanel({
		frame : true,
		width : 950,
		labelWidth : 85,
		items : [{layout:'column',defaults:{layout:'form'},
			      items:[{columnWidth:0.3,items:[searchName]},
			             {columnWidth:0.3,items:[searchArea]},
			             {columnWidth:0.3,items:[searchComplateDate]},
			             {columnWidth:0.1,items:[btn_search]}]
				},comGrid,ps.projectInfo,ps.projectNeed,
		         ps.projectIsVs,ps.projectVsInfo,fileUploadInfo],
  	   listeners: {
 	    	render: {fn:function(){ 
					ps.getGridArea.load();
					completeStore.load();
 					//strackStore.load();
 			}}
 		}
	});
	//检索项目
	var searchProject = function(){
		completeStore.reload();
	};
};